package dyyx.discard;

import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;

/**
 * Handles a server-side channel.
 */
public class MyDiscardServerHandler extends ChannelInboundHandlerAdapter {
	
	private static long seq = 0;

    @Override
    public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
        // discard
    	// 没有release  堆外内存会溢出
    	// java.lang.OutOfMemoryError: Direct buffer memory
    	// System.out.println(msg.toString());
    	System.out.println((seq++)+DiscardServer.getInfo(msg));
    	
    	// System.gc();

    }

    @Override
    public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
        // Close the connection when an exception is raised.
        cause.printStackTrace();
        ctx.close();
    }
}
